package com.Domain;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

import com.EdificacioAR.DebugLog;

/**
 *
 * @author faust
 */
@Root (name="Channel")
public class Channel {

	@Element (name="name")
    private String name;
    @ElementList (name="layers")
    private List<Layer> layers;
    
    private int selectedLayer;

    public Channel() {
        name = "";
        layers = new ArrayList<Layer>();
        selectedLayer = 0;
    }
    
    public Channel(String name, List<Layer> layers) {
        this.name = name;
        this.layers = new ArrayList<Layer>(layers);
        this.selectedLayer = 0;
    }

    public List<Layer> getLayers() {
        return layers;
    }

    public void setLayers(List<Layer> layers) {
        this.layers = layers;
    }

    public Layer getLayer(int i) {
        return layers.get(i);
    }
    
    public int getLayerCount() {
    	return layers.size();
    }

    public void removeLayer(int i) {
        layers.remove(i);
    }

    public void addLayer(Layer m) {
        layers.add(m);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    /*public int getSelectedLayer() {
    	return this.selectedLayer;
    }
    
    public void setSelectedLayer(int selectedLayer) {
    	this.selectedLayer = selectedLayer;
    }
    
    public float getSelectedScaleFactor() {
		return this.layers.get(getSelectedLayer()).getSelectedScaleFactor();
	}

	public void setSelectedScaleFactor(float scaleFactor) {
		this.layers.get(getSelectedLayer()).setSelectedScaleFactor(scaleFactor);
	}
	
	public float getSelectedTranslateX() {
		return this.layers.get(getSelectedLayer()).getSelectedTranslateX();
	}
	
	public float getSelectedTranslateY() {
		return this.layers.get(getSelectedLayer()).getSelectedTranslateY();
	}
	
	public void setSelectedTranslate(float incX, float incY) {
		this.layers.get(getSelectedLayer()).setSelectedTranslate(incX, incY);	
	}
    
    public int getSelectedModel() {
    	return this.layers.get(this.selectedLayer).getSelectedModel();
    }
    
    public void setSelectedModel(int selectedModel) {
    	this.layers.get(this.selectedLayer).setSelectedModel(selectedModel);
    }
    
    public void selectNextModel() {
    	this.layers.get(this.selectedLayer).selectNextModel();
    }    
    
    public void selectPreviousModel() {
    	this.layers.get(this.selectedLayer).selectPreviousModel();
    }*/
    
    /** Load the model data of every Model on this channel*/
    public void load() {
    	for (Layer l : layers) l.load();
    }

    @Override
    public String toString() {

        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");

        result.append("Channel {" + NEW_LINE);
        result.append(" - name: " + name + NEW_LINE);
        result.append(" - layers:" + layers.toString() + NEW_LINE);
        result.append("}");

        return result.toString();
    }

}
